<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="renderer" content="webkit|ie-comp|ie-stand" />
		<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
		<title>个人信息修改</title>
	<%@ include file="/common/commonLib.jsp"%> 
		<link rel="stylesheet" type="text/css" href="<c:url value='/css/personal-info.css'/>" />

	</head>

	<body>
		<div class="container-fluid">
			<div class="row">
				<div class="col-xs-12 info-title">
					<div class="col-xs-12 col-sm-6 col-md-6 col-lg-3 info-title-left">
						<shiro:hasRole name="teacher">
							<a href="${pageContext.request.contextPath}/course/list">精准微课堂</a>
						</shiro:hasRole>
						<shiro:hasRole name="assistant">
							<a href="${pageContext.request.contextPath}/accontrol/ajaxListCourseView">精准微课堂</a>
						</shiro:hasRole>
						<shiro:hasRole name="student">
							<a href="${pageContext.request.contextPath}/lesson/studentCLesson">精准微课堂</a>
						</shiro:hasRole>
					</div>
					<div class="col-xs-12 col-sm-6 col-md-6 col-lg-2 col-lg-push-7 info-title-right">
						<img src="<c:url value="/resource/picture/${image}" />" />${name}
					</div>
					<div class="col-xs-12 col-sm-12 col-md-12 col-lg-7 col-lg-pull-2 info-title-mid">
						
					</div>
				</div>
			</div>

			<div class="row">
				<div class="col-md-3 col-lg-4 col-sm-2"></div>
				<div class="col-md-6 col-lg-4 col-sm-8">
					<div class="info-title personal-info-title">
						个人信息修改
					</div><br />
					<div class="row">
						<div class="col-xs-1 col-sm-1"></div>
						<div class="col-md-12 col-xs-10 col-lg-12 col-sm-10">
							<form>
								<div class="form-group" style="display:none;">
									<div class="row">
										<div class="col-md-5 col-xs-6 col-sm-3">
											<label for="account">教工号/学号</label>
										</div>
										<div class="col-md-7 col-xs-10 col-sm-7">
											<input type="text" class="form-control" name="userCode" placeholder="教工号/学号">
										</div>
										<div class="col-xs-2 col-sm-2"></div>
									</div>
								</div>
								<div class="form-group" style="display:none;">
									<div class="row">
										<div class="col-md-5 col-xs-6 col-sm-3">
											<label for="name">密码</label>
										</div>
										<div class="col-md-7 col-xs-10 col-sm-7">
											<input type="password" class="form-control" name="password" placeholder="密码">
										</div>
										<div class="col-xs-2 col-sm-2"></div>
									</div>
								</div>
								<div class="form-group">
									<div class="row">
										<div class="col-md-5 col-xs-6 col-sm-3">
											<label for="name">姓名</label>
										</div>
										<div class="col-md-7 col-xs-10 col-sm-7">
											<input type="text" class="form-control" name="name" placeholder="姓名">
										</div>
										<div class="col-xs-2 col-sm-2"></div>
									</div>
								</div>
								<div class="form-group">
									<div class="row">
										<div class="col-md-5 col-xs-6 col-sm-3">
											<label for="sex">性别</label>
										</div>
										<div class="col-md-7 col-xs-10 col-sm-7">
											<select id="gender" class="form-control">
												<option value="MALE">男</option>
												<option value="FEMALE">女</option>
											</select>
										</div>
										<div class="col-xs-2 col-sm-2"></div>
									</div>
								</div>
								<div class="form-group">
									<div class="row">
										<div class="col-md-5 col-xs-6 col-sm-3">
											<label for="phone">班号</label>
										</div>
										<div class="col-md-7 col-xs-10 col-sm-7">
											<input type="text" class="form-control" name="classNumber" placeholder="班号">
										</div>
										<div class="col-xs-2 col-sm-2"></div>
									</div>
								</div>
								<div class="form-group">
									<div class="row">
										<div class="col-md-5 col-xs-6 col-sm-3">
											<label for="phone">电话</label>
										</div>
										<div class="col-md-7 col-xs-10 col-sm-7">
											<input type="tel" class="form-control" name="mobilePhone" placeholder="电话">
										</div>
										<div class="col-xs-2 col-sm-2"></div>
									</div>
								</div>
								<div class="form-group">
									<div class="row">
										<div class="col-md-5 col-xs-6 col-sm-3">
											<label for="email">邮箱</label>
										</div>
										<div class="col-md-7 col-xs-10 col-sm-7">
											<input type="email" class="form-control" name="email" placeholder="邮箱">
										</div>
										<div class="col-xs-2 col-sm-2"></div>
									</div>
								</div>
								<div class="form-group">
									<div class="row">
										<div class="col-md-5 col-xs-6 col-sm-3">
											<label for="qq">QQ</label>
										</div>
										<div class="col-md-7 col-xs-10 col-sm-7">
											<input type="text" class="form-control" name="qq" placeholder="QQ">
										</div>
									</div>
									<div class="col-xs-2 col-sm-2"></div>
								</div>
							</form>
						</div>
						<div class="col-xs-1 col-sm-1"></div>

					</div>
					<br />
					<div class="row">
						<div class="col-md-1 col-xs-1"></div>
						<div class="col-md-4 col-xs-3">
							<shiro:hasRole name="teacher">
								<button type="button" class="btn btn-default" onclick="javascript:window.location.href='${pageContext.request.contextPath}/course/list';">返回</button>
							</shiro:hasRole>
							<shiro:hasRole name="assistant">
								<button type="button" class="btn btn-default" onclick="javascript:window.location.href='${pageContext.request.contextPath}/accontrol/ajaxListCourseView';">返回</button>
							</shiro:hasRole>
							<shiro:hasRole name="student">
								<button type="button" class="btn btn-default" onclick="javascript:window.location.href='${pageContext.request.contextPath}/lesson/studentCLesson';">返回</button>
							</shiro:hasRole>
						</div>
						<div class="col-md-2 col-xs-2"></div>
						<div class="col-md-4 col-xs-3">
							<button type="submit" id="editPersonalInfo" class="btn btn-primary">修改</button>
						</div>
						<div class="col-md-1 col-xs-3"></div>
					</div>
					<br /><br />
				</div>
				<div class="col-md-3 col-lg-4 col-sm-2"></div>
			</div>
		</div>
		</div>
	</body>
<script>
var data=${data};

$(document).ready(function(){
	
	$("#editPersonalInfo").on("click",editPersonalInfoEvent);  
	initPage(data.data.user);
})

var initPage=function(user){
	$("input[name='name']").val(user.name);
	$("input[name='classNumber']").val(user.classNumber);
	$("input[name='mobilePhone']").val(user.mobilePhone);
	var selections= document.getElementById("gender").options;
	var userGender = user.gender;
	for(var i=0;i<selections.length; i++){  
        var tempValue = selections[i].value;  
        if(tempValue == userGender)  
        {  
        	selections[i].selected = true;  
        }  
    }
	$("input[name='email']").val(user.email);
	$("input[name='qq']").val(user.qq);
}

var editPersonalInfoEvent=function(){
	var id=${sessionScope.id};
	var userCode =$("input[name='userCode']").val();
	var password =$("input[name='password']").val();
	var name =$("input[name='name']").val();
	var classNumber =$("input[name='classNumber']").val();
	var mobilePhone =$("input[name='mobilePhone']").val();
	var email =$("input[name='email']").val();
	var qq =$("input[name='qq']").val();
	var gender =$("#gender  option:selected").val();
	var json={
			 id:id,
			 userCode:userCode,
			 password:password,
			 name:name,
			 classNumber:classNumber,
			 mobilePhone:mobilePhone,
			 email:email,
			 qq:qq,
			 gender:gender
	 }
	
	 $.post("<c:url value='/user/update' />", {
			data : JSON.stringify(json)
		}, function(data) {
			if(data.status=="success"){
				alert("修改成功，重新登陆可生效！");
				window.location.href = CONTEXT_PATH + "user/logout";
			}else{
				alert("wrong");
			}
		}); 
}

</script>
</html>